//ST*****************************************单选按钮*****************************************
function RxRadio() {
}

RxRadio.init = function (id, groupName, checked, value, text, style, callback) {
    var ctrl = document.getElementById(id);
    if (ctrl == undefined || ctrl == null || ctrl == "") {
        ctrl = document.createElement("div");
    }

    ctrl.dispose = RxCommon.dispose;
    ctrl.dispose();

	if (id) {
    	ctrl.id = id;
	}
	ctrl.rxtype = "RxRadio";
    ctrl.groupName = groupName;
    ctrl.controlType = "rxradio";
    ctrl.value = value;
    ctrl.text = text;
    ctrl.callback = callback;

    if (style) {
        RxCommon.setStyle(ctrl, style);
    }

	ctrl.ce = RxCommon.ce;

    ctrl.label = ctrl.ce(ctrl,null, "div", "rxradio_text");
    ctrl.label.innerHTML = text;
    RxCommon.disableSelection(ctrl.label);

    ctrl.onclick = function() {
        this.checked = true;
        this.refresh();
        if (this.callback) {
			var rxevent = {};
			rxevent.id = this.id;
			rxevent.name = "click";
			rxevent.self = this._self;
			rxevent.target = this;
			rxevent.source = this;
			rxevent.value = this.value;
			rxevent.text = this.text;
			rxevent.checked = this.checked;
            this.callback(rxevent);
        }
    };

    ctrl.refresh = function() {
        if (this.checked == true) {
            this.className = "rxradio_on";
        } else {
            this.className = "rxradio_off";
            return;
        }

        var data = this.getRadios();
        for (var i = 0; i < data.radios.length; i++) {
            if (this == data.radios[i]) {
            } else {
                data.radios[i].checked = false;
                data.radios[i].className = "rxradio_off";
            }
        }
    };

    ctrl.getValue = function() {
        var data = this.getRadios();
        if (data.self) {
            return data.self.value;
        }
        return null;
    };

    ctrl.getData = function() {
        var data = this.getRadios();
        if (data.self) {
            return {code:data.self.value,name:data.self.text};
        }
        return null;
    };

    ctrl.getRadios = function() {
        var data = {self:null, radios:[]};
        var radios = $(".rxradio_on,.rxradio_off");
        for (var i = 0; i < radios.length; i++) {
            if (radios[i].groupName == this.groupName) {
                data.radios[data.radios.length] = radios[i];
                if (radios[i].checked) {
                	data.self = radios[i];
                }
            }
        }
        return data;
    };

    ctrl.checked = (checked==true) ? true : false;
    ctrl.refresh();

    return ctrl;
};
//ED*****************************************单选按钮*****************************************
